package demo13

// 策略者设计模式
// strategy PaymentStrategy  Payment PaymentContext 
// Cash Bank
import "fmt"
// 支付架构
type Payment struct{
	context *PaymentContext // 支付的内容
	strategy PaymentStrategy // 支付方式
}

type PaymentContext struct{
	Name, CardID string
	Money float64
}

func NewPayment(name,cardId string,money float64,strategy PaymentStrategy)*Payment{
	return &Payment{
		context: &PaymentContext{
			Name:name,
			CardID:cardId,
			Money:money,
		},
		strategy: strategy,
	}
}

func (p *Payment)Pay(){
	p.strategy.Pay(p.context)
}

type PaymentStrategy interface{
	Pay(*PaymentContext)
}

type Cash struct{
	// 定义区分
	method string
}
func NewCash(method string) *Cash{
	return &Cash{
		method:method,
	}
}
func (c *Cash)Pay(ctx *PaymentContext){
	fmt.Printf("name:%s cardid:%s money:%f\n",ctx.Name,ctx.CardID,ctx.Money - 100)
}

type Bank struct{
	method string
}
func NewBank(method string) *Bank{
	return &Bank{
		method:method,
	}
}

func (b *Bank)Pay(ctx *PaymentContext){
	fmt.Printf("name:%s cardid:%s money:%f\n",ctx.Name,ctx.CardID,ctx.Money)
}